<template>
	<view class="content">
		<view v-if="favorites.length === 0" class="empty">暂无收藏</view>
		<view v-else class="uni-list">
			<view class="uni-list-cell card"
				  v-for="(item, index) in favorites" 
				  :key="index"
				  @tap="openinfo" :data-newsid="item.post_id">
				<view class="uni-media-list">
					<image class="uni-media-list-logo" :src="item.autor_avatar"></image>
					<view class="uni-media-list-body">
						<view class="uni-media-list-text-top">{{ item.title }}</view>
						<view class="uni-media-list-text-bottom">{{ formatDate(item.created_at) }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			favorites: uni.getStorageSync('favorites') || []
		};
	},
	methods: {
		formatDate(date) {
			const options = { year: 'numeric', month: 'short', day: 'numeric' };
			return new Date(date).toLocaleDateString('zh-CN', options);
		},
		openinfo(e) {
			const newsid = e.currentTarget.dataset.newsid;
			uni.navigateTo({ url: `../info/info?newsid=${newsid}` });
		}
	}
}
</script>

<style>
.empty { text-align: center; color: #999; font-size: 16px; margin-top: 20px; }
</style>
